The disclosed subject matter relates generally to hardware transactional memory systems and, more particularly, to compiler support for a hardware transactional memory system.
Transactional memory is generally an attempt to simplify parallel programming by allowing a group of load and store instructions to execute in an atomic way. There are two types of transactional memory: hardware (HTM) and software (STM).
An STM system provides transactional memory semantics in a software runtime library or the programming language. Unlike locking techniques used in most modern multithreaded applications, STM is very optimistic: a thread completes modifications to shared memory without regard for what other threads might be doing, recording every read and write that it is performing in a log. Instead of placing the onus on the writer to make sure it does not adversely affect other operations in progress, it is placed on the reader, who after completing an entire transaction verifies that other threads have not concurrently made changes to memory that it accessed in the past. This final operation, in which the changes of a transaction are validated and, if validation is successful, made permanent, is called a commit. A transaction may also abort at any time, causing all of its prior changes to be rolled back or undone. If a transaction cannot be committed due to conflicting changes, it is typically aborted and re-executed from the beginning until it succeeds.
An HTM system typically starts a transaction by taking a register checkpoint. Whenever the transaction writes to memory, the transactional data produced by the write operation is maintained separately from the old data by either buffering the transactional data or logging the old value (i.e., data versioning). The HTM system records the memory addresses that are read by the transaction in a read-set. Likewise, the HTM system also records the memory addresses that are written to in a write-set. The HTM system detects a conflict between two transactions by comparing the read-sets and the write-sets of both transactions (i.e., conflict detection). A conflict occurs when two different transactions access the same address and at least one of the transactions intends to write to the address. If a conflict is detected, one of the transactions is rolled back by undoing transactional write operations, restoring the register checkpoint, and discarding transactional metadata (e.g., the read-/write-sets). Absent a conflict, each transaction ends by committing transactional data and discarding transactional metadata and the register checkpoint.
Both systems enjoy certain advantages. For example, STM systems can be implemented with minimal alterations to the hardware on which it will be operated. HTM systems, on the other hand, may require modifications in processors, cache or bus protocol to support new “atomic” transactions. That is, HTM systems require modification to the hardware, whereas STM systems can be implemented on existing hardware. As a consequence, HTM systems with their specialized hardware may experience improved performance of STM systems, but the relative ease of implementing STM systems has allowed STM systems to be developed and implemented more rapidly. Further, because of the more rapid development of STM systems, supporting software, such as compilers necessary to transform source code into executable code have been investigated and developed specifically for use on STM systems. HTM systems have lagged behind, such that compilers are not currently commercially available.